//
//  XMNetwork+home.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/10.
//

#import "XMNetwork+home.h"

@implementation XMNetwork (home)

///**
// 首页关注
// */
//- (void)getHomeAttentionWithPage:(NSString *)pageStr success:(void (^)(id _Nonnull))successBlock failure:(void (^)(NSError * _Nonnull))failureBlock {
//    NSMutableDictionary *paramters = [NSMutableDictionary dictionary];
//    [paramters safe_setObject:pageStr forKey:@"pageNum"];
//    [paramters safe_setObject:@"10" forKey:@"pageSize"];
//    [self postDataWithPath:getHomeAttentionUrl
//                parameters:paramters
//                 needToken:NO
//                   headers:@{}
//                   success:^(id  _Nonnull responseObject) {
//        successBlock (responseObject);
//    } failure:^(NSError * _Nonnull error) {
//        failureBlock (error);
//    }];
//}
//
///**
// 首页新发布的见面
// */
//- (void)getNewPubMeetingWithPage:(NSString *)pageStr
//                         success:(void (^)(id _Nonnull))successBlock
//                         failure:(void (^)(NSError * _Nonnull))failureBlock {
//    NSMutableDictionary *paramters = [NSMutableDictionary dictionary];
//    [paramters safe_setObject:pageStr forKey:@"pageNum"];
//    [paramters safe_setObject:@"10" forKey:@"pageSize"];
//    [self postDataWithPath:getHomeNewPubUrl
//                parameters:paramters
//                 needToken:NO
//                   headers:@{}
//                   success:^(id  _Nonnull responseObject) {
//        successBlock (responseObject);
//    } failure:^(NSError * _Nonnull error) {
//        failureBlock (error);
//    }];
//}
/**
 首页关注数据
 */
- (void)getHomeDataWithType:(NSInteger)type
                       page:(NSString *)pageStr
                  longitude:(nonnull NSString *)longitude
                   latitude:(nonnull NSString *)latitude
                    success:(void (^)(id _Nonnull))successBlock
                    failure:(void (^)(NSError * _Nonnull))failureBlock {
    BOOL needToken = NO;
    NSString *path = getHomeAttentionUrl;
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    switch (type) {
        case 0: {
            needToken = YES;
        }
            break;
        case 1: {
            path = getHomeRecommendUrl;
        }
            break;
        case 2: {
            path = getHomeDistanceUrl;
            [parameters safe_setObject:latitude forKey:@"lat"];
            [parameters safe_setObject:longitude forKey:@"lon"];
            [parameters safe_setObject:@"1000" forKey:@"distance"];
        }
            break;
        case 3: {
            path = getHomeNewPubUrl;
        }
            break;
            
        default:
            break;
    }
    [parameters safe_setObject:pageStr forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    
    [self postDataWithPath:path
                parameters:parameters
                 needToken:needToken
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 见面详情
 */
- (void)getMeetDetailWithServiceId:(NSString *)serviceId
                           success:(void (^)(id _Nonnull))successBlock
                           failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:serviceId forKey:@"serviceId"];
    [self getDataWithPath:getMeetDetailInfoUrl
               parameters:parameters
                needToken:NO
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 收藏见面
 */
- (void)collectionMeetWithServiceId:(NSString *)serviceId
                            success:(void (^)(id _Nonnull))successBlock
                            failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:serviceId forKey:@"serviceId"];
    [self getDataWithPath:collectionMeetUrl
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 取消收藏见面
 */
- (void)cancelCollectMeetWithServiceId:(NSString *)serviceId success:(void (^)(id _Nonnull))successBlock failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:serviceId forKey:@"serviceId"];
    [self getDataWithPath:cancelCollectionService
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
加入见面箱
 */
- (void)addMeetBoxWithServiceId:(NSString *)serviceId success:(void (^)(id _Nonnull))successBlock failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:serviceId forKey:@"serviceId"];
    [parameters safe_setObject:@"1" forKey:@"productNum"];
    [self postDataWithPath:addMeetBoxUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 创建订单
 */
- (void)creatOrderWithCartIds:(NSString *)cartIds
                    addressId:(NSString *)addressId
                      payType:(NSString *)payType
                      success:(void (^)(id _Nonnull))successBlock
                      failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSArray *cartIdArr = [cartIds componentsSeparatedByString:@","];
    [parameters safe_setObject:cartIdArr forKey:@"cartIds"];
//    [parameters safe_setObject:addressId forKey:@"addressId"];
    [parameters safe_setObject:payType forKey:@"payType"];
    [self postDataWithPath:creatOrderUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 获取支付信息
 */
- (void)getPayInfoWithOrderId:(NSString *)orderId
                      success:(void (^)(id _Nonnull))successBlock
                      failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:orderId forKey:@"orderId"];
    [parameters safe_setObject:@"app" forKey:@"type"];
    [self getDataWithPath:getPayInfoUrl
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 直接创建订单
 */
- (void)creatOrderWithServiceId:(NSString *)serviceId success:(void (^)(id _Nonnull))successBlock failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:serviceId forKey:@"serviceId"];
    [parameters safe_setObject:@"1" forKey:@"payType"];
    [self postDataWithPath:creatDirectOrderUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 他人个人信息
 */
- (void)getOtherUserInfoWithUserId:(NSString *)userId
                           success:(void (^)(id _Nonnull))successBlock
                           failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:userId forKey:@"userId"];
    [self getDataWithPath:getOtherUserInfoUrl
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 他人的作品
 */
- (void)getOtherVideoWithUserId:(NSString *)userId
                        success:(void (^)(id responseObject))successBlock
                        failure:(void (^)(NSError *error))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:userId forKey:@"userId"];
    [self getDataWithPath:getOtherVideoUrl
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 聊天密钥
 */
- (void)getUserSigWithUserId:(NSString *)userId
                     success:(void (^)(id _Nonnull))successBlock
                     failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:userId forKey:@"id"];
    [self getDataWithPath:getUserSigUrl
               parameters:parameters
                needToken:YES
                  headers:@{}
                  success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 单发单聊消息
 */
- (void)sendMessageWithSender:(NSString *)senderId
                     receiver:(NSString *)receiverId
                      message:(NSString *)message
                      success:(void (^)(id _Nonnull))successBlock
                      failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:@"1" forKey:@"syncOtherMachine"];
    [parameters safe_setObject:senderId forKey:@"fromUserId"];
    [parameters safe_setObject:receiverId forKey:@"toUserId"];
    [parameters safe_setObject:@"1" forKey:@"msgType"];
    [parameters safe_setObject:message forKey:@"msgContent"];
    [_Network getDataWithPath:sendMessageUrl
                   parameters:parameters
                    needToken:YES
                      headers:@{}
                      success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 获取历史消息
 */
- (void)getHistoryMessageWithSender:(NSString *)senderId
                           receover:(NSString *)receiverId
                         lastMsgKey:(NSString *)lastMsgKey
                            success:(void (^)(id _Nonnull))successBlock
                            failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSInteger currentTime = [[NSDate date] timeIntervalSince1970];
    [parameters safe_setObject:senderId forKey:@"operatorAccount"];
    [parameters safe_setObject:receiverId forKey:@"peerAccount"];
    [parameters safe_setObject:@(10) forKey:@"maxCnt"];
    [parameters safe_setObject:@(0) forKey:@"minTime"];
    [parameters safe_setObject:@(currentTime) forKey:@"maxTime"];
    [parameters safe_setObject:lastMsgKey forKey:@"lastMsgKey"];
    [self postDataWithPath:getHistoryMsgUrl
                parameters:parameters
                 needToken:YES
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

/**
 见面包搜索
 */
- (void)meetSearchWithSearchKey:(NSString *)searchKey
                    isAscending:(NSString *)isAscending
                           city:(NSString *)city
                           page:(NSString *)pageStr
                        success:(void (^)(id _Nonnull))successBlock
                        failure:(void (^)(NSError * _Nonnull))failureBlock {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safe_setObject:searchKey forKey:@"keyword"];
    [parameters safe_setObject:pageStr forKey:@"pageNum"];
    [parameters safe_setObject:@"10" forKey:@"pageSize"];
    [parameters safe_setObject:isAscending forKey:@"isAscending"];
    [parameters safe_setObject:city forKey:@"city"];
    [self postDataWithPath:meetSearchUrl
                parameters:parameters
                 needToken:NO
                   headers:@{}
                   success:^(id  _Nonnull responseObject) {
        successBlock (responseObject);
    } failure:^(NSError * _Nonnull error) {
        failureBlock (error);
    }];
}

@end
